﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Mod_SellManage_frm_SellContract : System.Web.UI.Page
{

    #region  票据核销业务逻辑主体部分

    public void AddSellContractInfo(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();

            ImageButton ibtnAdd = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnAdd.CommandName);

            if (intCommandName == 0)//打开主表添加面板
            {
                if (!this.panAddResult.Visible)
                {
                    string strCode = cls_Menu.GetSystemCode("0", "00", "", 14);//获取系统编码

                    if (strCode != "Error")
                    {
                        this.panAddResult.Visible = true;
                        this.ctbAdd0.Text = strCode;
                        this.ctsbAdd0.Text = this.ctsbAdd1.Text = this.ctbAdd10.Text = DateTime.Now.ToString();
                        this.ctbAdd9.Text = strUserID;
                        this.lblJs.Text = "<script>document.getElementById('" + this.ctsbAdd2.ClientID + "_txtBox').focus();</script>";
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                    }
                }
            }
            else if (intCommandName == 1)//关闭主表添加面板
            {
                this.panAddResult.Visible = false;

                string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            }
            else if (intCommandName == 2)//保存主表添加记录
            {
                string co_no = this.ctbAdd0.Text.Trim();
                DateTime co_date = DateTime.Parse(this.ctsbAdd1.Text.Trim());

                bool type = (Int32.Parse(this.hidType.Value) == 0) ? false : true;

                string cm_no = this.CuTextSelectBox1.Text.Trim();
                DateTime cm_date = DateTime.Parse(this.ctsbAdd0.Text.Trim());

                decimal djje = decimal.Parse(this.ctsbAdd4.Text.Trim());
                decimal bchxje = decimal.Parse(this.ctsbAdd5.Text.Trim());
                string remark = this.ctbAdd11.Text.Trim();

                Boolean bolIsSucceed = cls_SellManage.AddOrUpdateSellContract(co_no, co_date, type, cm_no, cm_date, strUserID, remark, 0);

                if (bolIsSucceed)
                {
                    this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果


                    this.ctsbAdd0.Text = ctsbAdd1.Text = ctsbAdd2.Text = ctsbAdd5.Text = "";
                    this.ctbAdd11.Text = "";

                    //主表新增后直接打开从表进行新增从表记录 Begin///////////////////////////
                    this.panAddResult.Visible = false;
                    ImageButton ibtn = new ImageButton();

                    int intItems = this.dgrdResult.Items.Count - 1;

                    for (int i = intItems; i >= 0; i--)
                    {
                        string strRs_DmNO = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();

                        if (strRs_DmNO == co_no)
                        {
                            ibtn = (ImageButton)this.dgrdResult.Items[i].FindControl("ibtnOpenChild");

                            break;
                        }
                    }

                    // this.OpenChildResult(ibtn, null);
                    this.AddSellContractInfo(this.ibtnAdd, null);
                    //主表新增后直接打开从表进行新增从表记录 End///////////////////////////
                }
                else
                {
                    this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                }
            }
            //////////////////////////////////////////从表相关操作/////////////////////////////////////
            else
            {
                int intIndex = Int32.Parse(this.ibtnAdd.CommandArgument);

                Panel panChildAddResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panChildAddResult");

                if (intCommandName == 3)//关闭从表添加面板
                {
                    panChildAddResult.Visible = false;
                }
                else if (intCommandName == 4)//保存从表添加记录
                {

                    //CuTextSelectBox Im_No = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0");


                    CuTextBox co_noN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");

                    //HtmlInputHidden hidChildTypeN = (HtmlInputHidden)this.dgrdResult.Items[intIndex].FindControl("hidChildType");
                    CuTextSelectBox g_noN = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0");

                    CuTextBox im_noN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd0");
                    CuTextBox im_dateN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd2");
                    CuTextBox ct_idN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd0");
                    CuTextBox omoneyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd7");
                    CuTextBox moneyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd3");
                    CuTextBox priceN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox1");
                    CuTextBox remarkN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd8");

                    CuTextBox a_moneyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox3");
                    CuTextBox b_moenyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox4");
                    CuTextBox c_moneyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox5");
                    CuTextBox d_moneyN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox6");



                    bool ChildType = (Int32.Parse(this.hidChildType.Value) == 0) ? true : false;
                    string co_no = co_noN.Text.Trim();
                    string g_no = g_noN.Text.Trim();
                    string im_no = im_noN.Text.Trim();
                    DateTime im_date = DateTime.Parse(im_dateN.Text.Trim());
                    decimal omoney = decimal.Parse(omoneyN.Text.Trim());
                    decimal money = decimal.Parse(moneyN.Text.Trim());
                    decimal price = decimal.Parse(priceN.Text.Trim());
                    decimal a_money = decimal.Parse(a_moneyN.Text.Trim());
                    decimal b_money = decimal.Parse(b_moenyN.Text.Trim());
                    decimal c_money = decimal.Parse(c_moneyN.Text.Trim());
                    decimal d_money = decimal.Parse(d_moneyN.Text.Trim());

                    string ct_id = ct_idN.Text.Trim();
                    string remark = remarkN.Text.Trim();


                    if ((price > money) ? false : true)
                    {
                        Boolean bolIsSucceed = cls_SellManage.AddOrUpdateSellContracChild(co_no, g_no, ChildType, im_no, im_date, omoney, money, price, a_money, b_money, c_money, d_money, remark, 0);

                        if (bolIsSucceed)
                        {


                            DataSet dst = cls_SellManage.GetSellContractDataSetChild(co_no);//重新绑定从表结果

                            if (dst != null && dst.Tables[0].Rows.Count > 0)
                            {
                                DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");

                                this.BindSellContractChildByDataView(dgrd, dst, 0);
                            }

                            ((ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild")).Attributes.Remove("OnClick");

                            this.lblJs.Text = "<script>document.getElementById('" + g_noN.ClientID + "_txtBox').focus();</script>";
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                        }
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('剩余的已收款数额不足，请重试！')</script>";
                    }
                }
                else if (intCommandName == 5)//打开从表添加面板
                {
                    panChildAddResult.Visible = true;

                    CuTextSelectBox ctsbChildAdd0 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0");
                    this.lblJs.Text = "<script>document.getElementById('" + ctsbChildAdd0.ClientID + "_txtBox').focus();</script>";
                }
            }
        }
        else
        {
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    public void UpDateSellContractInfo(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ImageButton ibtnUpdate = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnUpdate.CommandName);
            int intIndex = Int32.Parse(ibtnUpdate.CommandArgument);

            if (intCommandName == 0)//主表确认
            {
                int intCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intCount; i++)
                {
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;

                    if (IsChecked)
                    {
                        string strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();

                        ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();

                        //判断此合同订单是否存在子单，不存在则不允许确认
                        int intExistCount = cls_SellManage.SellContractExistState(strCm_No, 2);

                        if (intExistCount != 0)
                        {
                            Boolean bolIsSucceed = cls_SellManage.UpdateSellContractState(strCm_No, 0, strUserID);

                            if (!bolIsSucceed)
                            {
                                this.lblJs.Text = "<script>alert('确认失败，请重试！')</script>";
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('无子单不能确认！')</script>";
                        }
                    }
                }

                this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果
            }
            else if (intCommandName == 3)//主表取消确认
            {
                string strCm_No = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0")).Text.Trim();

                ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();

                //判断此合同订单是否存在于销售发货，是则不允许反审
                //int intExistCount = cls_SellManage.SellContractExistState(strCm_No, 1);
                int intExistCouont = 0;

                if (intExistCouont == 0)
                {
                    Boolean bolIsSucceed = cls_SellManage.UpdateSellContractState(strCm_No, 1, strUserID);

                    if (bolIsSucceed)
                    {
                        this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('取消确认失败，请重试！')</script>";
                    }
                }
                else
                {
                    this.lblJs.Text = "<script>alert('此单不允许反审，请先删除此单销售发货记录！')</script>";
                }
            }
            else if (intCommandName == 1 || intCommandName == 2 || intCommandName == 4)//主表编辑
            {
                CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
                ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
                ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
                ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
                ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
                CuTextBox co_noN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");
                CuTextSelectBox co_dateN = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs1");
                TextBox typeeN = (TextBox)this.dgrdResult.Items[intIndex].FindControl("typee");

                CuTextSelectBox cm_noN = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("CuTextSelectBox2");
                CuTextSelectBox cm_dateN = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs0");
                CuTextSelectBox ct_idN = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs2");
                TextBox djjeN = (TextBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs4");
                TextBox bchxjeN = (TextBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs5");

                CuTextBox remarkN = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs11");

                string co_no = co_noN.Text.Trim();
                DateTime co_date = DateTime.Parse(co_dateN.Text.Trim());

                bool type = (typeeN.Text.Trim() == "贴现") ? true : false;//下拉条显示的值

                string cm_no = cm_noN.Text.Trim();
                DateTime cm_date = DateTime.Parse(cm_dateN.Text.Trim());
                string ct_id = ct_idN.Text.Trim();
                decimal djje = decimal.Parse(djjeN.Text.Trim());
                decimal bchxje = decimal.Parse(bchxjeN.Text.Trim());

                string remark = remarkN.Text.Trim();

                if (intCommandName == 1)//取消编辑
                {
                    this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果
                }
                else if (intCommandName == 2)//编辑
                {
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = true;
                    chkRsSelect.Visible = ibtnRsEdit.Visible = ibtnRsOAudit.Visible = false;
                    co_dateN.ReadOnly = remarkN.ReadOnly = false;
                    this.lblJs.Text = "<script>document.getElementById('" + co_dateN.ClientID + "_txtBox').select();document.getElementById('" + co_dateN.ClientID + "_txtBox').focus();</script>";

                }
                else//保存编辑
                {
                    ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();
                    Boolean bolIsSucceed = cls_SellManage.AddOrUpdateSellContract(co_no, co_date, type, cm_no, cm_date, strUserID, remark, 1);

                    if (bolIsSucceed)
                    {
                        this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定结果
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('修改记录失败，请重试！')</script>";
                    }
                }
            }
            //////////////////////////////////////////从表相关操作/////////////////////////////////////
            else
            {
                ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();
                DataGrid dgrd = new DataGrid();
                string strCm_No = "";
                int intItems = this.dgrdResult.Items.Count;

                for (int i = intItems - 1; i >= 0; i--)//找当前可见的子DataGrid
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        break;
                    }
                }

                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[intIndex].FindControl("chkChildRsSelect");//在子DataGrid中找要操作的控件
                ImageButton ibtnChildRsCancel = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsCancel");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsEdit");
                ImageButton ibtnChildRsServer = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsServer");
                CuTextSelectBox ctsbChildRs0 = (CuTextSelectBox)dgrd.Items[intIndex].FindControl("ctsbChildRs0");
                CuTextBox ctbChildRs4 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs4");

                CuTextBox ctbChildRs8 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs8");
                TextBox dp2tboxN = (TextBox)dgrd.Items[intIndex].FindControl("dp2tbox");
                CuTextBox ctbChildRs3 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs3");
                //CuTextBox ctbChildRs0 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs0");
                //CuTextBox im_noN = (CuTextBox)dgrd.Items[intIndex].FindControl("im");
                TextBox ctbIm_no = (TextBox)dgrd.Items[intIndex].FindControl("ctbIm_no");
                CuTextBox ctbChildRs2 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs2");
                CuTextBox ctbChildRs7 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs7");
                CuTextBox CuTextBox2 = (CuTextBox)dgrd.Items[intIndex].FindControl("CuTextBox2");

                if (intCommandName == 5)//取消编辑
                {
                    DataSet dst = cls_SellManage.GetSellContractDataSetChild(strCm_No);

                    if (dst != null && dst.Tables[0].Rows.Count > 0)
                    {
                        this.BindSellContractChildByDataView(dgrd, dst, 0);
                    }
                }
                else if (intCommandName == 6)//编辑
                {
                    this.hidChildType.Value = (dp2tboxN.Text.Trim() == "销售发票") ? "0" : "1";
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    ctbChildRs8.ReadOnly = CuTextBox2.ReadOnly = false;
                    this.lblJs.Text = "<script>document.getElementById('" + ctsbChildRs0.ClientID + "_txtBox').select();document.getElementById('" + ctsbChildRs0.ClientID + "_txtBox').focus();</script>";
                }
                else//保存编辑
                {

                    string co_no = strCm_No;
                    bool im_type = (dp2tboxN.Text.Trim() == "销售发票") ? true : false;//下拉条显示的值
                    string g_no = ctsbChildRs0.Text.Trim();
                    string strIm_no = ctbIm_no.ToolTip;
                    string s = ctbChildRs2.ToolTip;
                    DateTime im_date = DateTime.Parse(ctbChildRs3.Text.Trim());

                    string remark = ctbChildRs8.Text.Trim();

                    decimal omoney = decimal.Parse(ctbChildRs7.Text.Trim());
                    decimal money = decimal.Parse(ctbChildRs2.Text.Trim());
                    decimal price = decimal.Parse(CuTextBox2.Text.Trim());

                    //获得当前单据已核销金额
                    decimal vmoney = cls_SellManage.GetInvoiceVerificationMoneyD(g_no, im_type, strIm_no);

                    if (price <= money - vmoney)
                    {
                        Boolean bolIsSucceed = cls_SellManage.AddOrUpdateSellContracChild(co_no, g_no, im_type, strIm_no, im_date, omoney, money, price, 0, 0, 0, 0, remark, 1);

                        if (bolIsSucceed)//重新绑定从表结果
                        {
                            DataSet dst = cls_SellManage.GetSellContractDataSetChild(strCm_No);

                            if (dst != null && dst.Tables[0].Rows.Count > 0)
                            {
                                this.BindSellContractChildByDataView(dgrd, dst, 0);
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('修改记录失败，请重试！')</script>";
                        }
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('已收款金额不足，请重试！')</script>";
                    }
                }
            }
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    public void OpenChildResult(object sender, ImageClickEventArgs e)
    {
        ImageButton ibtnOpen = (ImageButton)sender;
        int intCommandName = Int32.Parse(ibtnOpen.CommandName);
        int intIndex = Int32.Parse(ibtnOpen.CommandArgument);
        int intCount = this.dgrdResult.Items.Count;
        bool is_audit = bool.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text);

        CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
        ImageButton ibtnOpenChild = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild");
        ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
        ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
        ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
        ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
        Panel panShowChildResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panShowChildResult");

        //获取从表信息
        CuTextBox ctbRs0 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");
        ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();
        DataSet dst = cls_SellManage.GetSellContractDataSetChild(ctbRs0.Text.Trim());

        if (dst == null || dst.Tables[0].Rows.Count <= 0)
        {
            ibtnOpen.Attributes.Add("OnClick", "return confirm('单据录入未完成，您要删除此单据吗？');");
        }

        if (intCommandName == 0)//展开
        {
            for (int i = 0; i < intCount; i++)//找到展开的项
            {
                Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                if (i == intIndex)
                {
                    panItem.Visible = true;
                }
                else
                {
                    panItem.Visible = false;
                }
            }

            this.ibtnAdd.CommandName = "5";//主表展开后则不可操作
            this.ibtnRef.CommandName = "1";
            this.ibtnAdd.CommandArgument = intIndex.ToString();
            panShowChildResult.Visible = true;
            ibtnOpenChild.CommandName = "1";
            ibtnOpenChild.ImageUrl = "../App_Images/ico/10.gif";
            ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            ibtnRsServer.ImageUrl = "../App_Images/ico/16.gif";
            ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
            ibtnRsCancel.ImageUrl = "../App_Images/ico/18.gif";
            this.ibtnAudit.ImageUrl = "../App_Images/b_21_3.gif";
            this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = false;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;

            if (is_audit)//如果主表确认后则从表不可操作
            {
                this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = false;
                this.ibtnAdd.ImageUrl = "../App_Images/b_18_3.gif";
                this.ibtnDelete0.ImageUrl = "../App_Images/b_19_5.gif";
                this.imgDelete.ImageUrl = "../App_Images/b_19_6.gif";
                this.imgDelete.Attributes.Add("OnMouseOver", "");
                this.imgDelete.Attributes.Add("OnMouseOut", "");
                this.imgDelete.Attributes.Add("OnClick", "");
            }

            //显示从表信息
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");

                this.BindSellContractChildByDataView(dgrd, dst, 0);//绑定从表信息
            }
        }
        else//收缩
        {
            CuTextSelectBox CuTextSelectBox2 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("CuTextSelectBox2");

            decimal dcm = cls_SellManage.GetInvoiceVerificationMoneyM(CuTextSelectBox2.Text.Trim());

            if (dcm >= 0)
            {
                this.ibtnAdd.CommandName = "0";
                this.ibtnRef.CommandName = "0";



                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    panShowChildResult.Visible = false;
                    ibtnOpenChild.CommandName = "0";
                    ibtnOpenChild.ImageUrl = "../App_Images/ico/9.gif";
                    ibtnRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                    ibtnRsServer.ImageUrl = "../App_Images/ico/11.gif";
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/8.gif";
                    ibtnRsCancel.ImageUrl = "../App_Images/ico/4.gif";
                    this.ibtnAudit.ImageUrl = "../App_Images/b_21_1.gif";
                    this.ibtnAdd.ImageUrl = "../App_Images/b_18_1.gif";
                    this.ibtnDelete0.ImageUrl = "../App_Images/b_19_1.gif";
                    this.imgDelete.ImageUrl = "../App_Images/b_19_4.gif";
                    this.imgDelete.Attributes.Add("OnMouseOver", "ChangImage(this, '../App_Images/b_19_3.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_2.gif')");
                    this.imgDelete.Attributes.Add("OnMouseOut", "ChangImage(this, '../App_Images/b_19_4.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_1.gif')");
                    this.imgDelete.Attributes.Add("OnClick", "ChildMenuVisible()");
                    this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = true;
                }
                else
                {
                    Boolean is_Succeed = cls_SellManage.UpdateSellContractState(ctbRs0.Text.Trim(), 3, "");
                }
                ClsPropertyDAL cls_Property = new ClsPropertyDAL();

                string strUserID = cls_Property.SetOrGetUserID;

                this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);//重新绑定数据
            }
            else
            {
                this.lblJs.Text = "<script>alert('贴现/兑现金额不足，请重试！')</script>";
            }
        }
    }

    private void GetSellContractInfoByMain(string strCurrUserID, int Type)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        cls_Property.SetOrGetDataSetType = Type;

        ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();

        DataSet dst = cls_SellManage.GetSellContractDataSet(strCurrUserID, Type);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            cls_Property.SetOrGetCorporationDataSet = dst;

            this.BindSellContractByDataView(dst, 0);
        }
        else
        {
            this.dgrdResult.CurrentPageIndex = 0;
            this.dgrdResult.DataSource = null;
            this.dgrdResult.DataBind();
            this.lblRsCounts.Text = "共0条记录";
            this.lblPageCounts.Text = "共0页";
            this.lblCurrPage.Text = "当前第0页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = false;
        }
    }

    private void DeleteStockCheckInfo(int CommandName)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();
            int intCount = this.dgrdResult.Items.Count;
            int intcommand = Int32.Parse(this.ibtnRef.CommandName);

            if (intcommand == 0)//删除主表
            {
                for (int i = 0; i < intCount; i++)
                {
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;

                    if (IsChecked)
                    {
                        Boolean bolIsSucceed = false;
                        string strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();

                        if (CommandName == 0)//不彻底删除
                        {
                            bolIsSucceed = cls_SellManage.UpdateSellContractState(strCm_No, 2, strUserID);
                        }
                        else//彻底删除
                        {
                            bolIsSucceed = cls_SellManage.UpdateSellContractState(strCm_No, 3, strUserID);
                        }

                        if (!bolIsSucceed)
                        {
                            this.lblJs.Text = "<script>alert('删除记录失败，请重试！')</script>";
                        }
                    }
                }

                //重新绑定主表结果
                this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else//删除从表
            {
                DataGrid dgrd = new DataGrid();
                string strCm_No = "";
                int intItems = this.dgrdResult.Items.Count;

                for (int i = intItems - 1; i >= 0; i--)//找当前可见的子DataGrid
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        break;
                    }
                }

                int intChildItems = dgrd.Items.Count;//循环删除所选的项

                for (int j = intChildItems - 1; j >= 0; j--)
                {
                    bool IsChecked = ((CheckBox)dgrd.Items[j].FindControl("chkChildRsSelect")).Checked;

                    string co_no = strCm_No;

                    if (IsChecked)
                    {
                        Boolean bolIsSucceed = false;
                        TextBox im_typeN = (TextBox)dgrd.Items[j].FindControl("dp2tbox");


                        bool im_type = (im_typeN.Text.Trim() == "销售发票") ? true : false;
                        string im_no = ((TextBox)dgrd.Items[j].FindControl("ctbIm_no")).ToolTip.Trim();
                        string g_no = ((CuTextSelectBox)dgrd.Items[j].FindControl("ctsbChildRs0")).Text.Trim();

                        if (CommandName == 0)//不彻底删除
                        {
                            bolIsSucceed = cls_SellManage.UpdateSellContractStateChild(co_no, g_no, im_type, im_no, 2);
                        }
                        else//彻底删除
                        {
                            bolIsSucceed = cls_SellManage.UpdateSellContractStateChild(co_no, g_no, im_type, im_no, 3);
                        }

                        if (!bolIsSucceed)
                        {
                            this.lblJs.Text = "<script>alert('删除记录失败，请重试！')</script>";
                        }
                    }
                }

                DataSet dst = cls_SellManage.GetSellContractDataSetChild(strCm_No);//重新绑定从表结果

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    this.BindSellContractChildByDataView(dgrd, dst, 0);
                }
                else
                {
                    dgrd.CurrentPageIndex = 0;
                    dgrd.DataSource = null;
                    dgrd.DataBind();
                }
            }
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void dgrdResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            bool Is_audit = bool.Parse(e.Item.Cells[1].Text.Trim());
            string strButtonEdit = this.hidButtonEdit.Value;
            string strButtonOAudit = this.hidButtonOAudit.Value;

            TextBox typee = (TextBox)e.Item.FindControl("typee");

            CheckBox chkRsSelect = (CheckBox)e.Item.FindControl("chkRsSelect");
            ImageButton ibtnRsEdit = (ImageButton)e.Item.FindControl("ibtnRsEdit");
            ImageButton ibtnRsCancel = (ImageButton)e.Item.FindControl("ibtnRsCancel");
            ImageButton ibtnRsServer = (ImageButton)e.Item.FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)e.Item.FindControl("ibtnRsOAudit");

            typee.Text = (e.Item.Cells[2].Text.Trim() == "False") ? "贴现" : "兑现";

            if (!Is_audit)
            {
                if (strButtonEdit.Trim() == "1")
                {
                    if (this.panAudit.Visible || this.panDelete.Visible)
                    {
                        chkRsSelect.Visible = true;
                    }

                    ibtnRsEdit.Visible = true;
                }
                else if (this.panAudit.Visible || this.panDelete.Visible)
                {
                    chkRsSelect.Visible = true;
                }
            }
            else
            {
                ibtnRsOAudit.Visible = true;

                if (strButtonOAudit.Trim() != "5")
                {
                    ibtnRsOAudit.Enabled = false;
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                }
            }
        }
    }

    protected void dgrdChildResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            TextBox dp2tbox = (TextBox)e.Item.FindControl("dp2tbox");
            //在数据库中 0表示false,1表示true 
            dp2tbox.Text = (e.Item.Cells[1].Text.Trim() == "true") ? "销售发票" : "应收期初";

        }
    }

    #endregion

    #region  票据核销业务逻辑其他部分

    public void ChangPage(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = this.dgrdResult.CurrentPageIndex;
            int intPageCounts = this.dgrdResult.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindSellContractByDataView(dst, intPageIndex);
        }
    }

    public void ChildChangPage(object sender, EventArgs e)
    {
        //获取保存的从表中的结果集和DataGrid控件
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetChildResultDataSet;
        DataGrid dgrd = cls_Property.SetOrGetChildDataGridControl;

        if (dst != null && dgrd != null)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = dgrd.CurrentPageIndex;
            int intPageCounts = dgrd.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindSellContractChildByDataView(dgrd, dst, intPageIndex);
        }
    }

    public void lbtnDelete_Click(object sender, EventArgs e)
    {
        int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    private void BindSellContractByDataView(DataSet dst, int CurrPageIndex)
    {
        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrdResult.CurrentPageIndex = CurrPageIndex;
            this.dgrdResult.DataSource = dst;
            this.dgrdResult.DataBind();

            this.lblRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条记录";
            this.lblPageCounts.Text = "共" + this.dgrdResult.PageCount + "页";
            this.lblCurrPage.Text = "当前第" + (this.dgrdResult.CurrentPageIndex + 1) + "页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = true;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = true;

            if (this.dgrdResult.PageCount == 1)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
                this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == this.dgrdResult.PageCount - 1)
            {
                this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == 0)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = false;
            }
        }
    }

    private void BindSellContractChildByDataView(DataGrid dgrd, DataSet dst, int CurrPageIndex)
    {
        if (dgrd != null && dst != null)
        {
            dgrd.CurrentPageIndex = CurrPageIndex;
            dgrd.DataSource = dst;
            dgrd.DataBind();

            int intIndex = Int32.Parse(dgrd.ToolTip);
            int intItems = dgrd.Items.Count;

            Label lblChildRsCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildRsCounts");
            Label lblChildPageCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildPageCounts");
            Label lblChildCurrPage = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildCurrPage");
            LinkButton lbtnChildFirst = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildFirst");
            LinkButton lbtnChildPrev = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildPrev");
            LinkButton lbtnChildNext = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildNext");
            LinkButton lbtnChildEnd = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildEnd");

            lblChildRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条明细记录";
            lblChildPageCounts.Text = "共" + dgrd.PageCount + "页";
            lblChildCurrPage.Text = "当前第" + (dgrd.CurrentPageIndex + 1) + "页";
            lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = true;
            lblChildRsCounts.Enabled = lblChildPageCounts.Enabled = lblChildCurrPage.Enabled = true;

            if (dgrd.PageCount == 1)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == dgrd.PageCount - 1)
            {
                lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == 0)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = false;
            }

            //判断从表中的记录是否可操作
            for (int i = 0; i < intItems; i++)
            {
                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[i].FindControl("chkChildRsSelect");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[i].FindControl("ibtnChildRsEdit");

                if (!this.ibtnAdd.Enabled)
                {
                    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = false;
                    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                }
                else
                {
                    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = true;
                    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                }
            }

            //保存从表中的结果集和DataGrid控件用于从表中的翻页
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();
            cls_Property.SetOrGetChildResultDataSet = dst;
            cls_Property.SetOrGetChildDataGridControl = dgrd;
        }
    }

    protected void txtGo_TextChanged(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strIndex = this.txtGo.Text.Trim();
            this.txtGo.Text = String.Empty;

            if (strIndex != "")
            {
                try
                {
                    int intIndex = Int32.Parse(strIndex) - 1;

                    if (intIndex >= 0 && intIndex < this.dgrdResult.PageCount)
                    {
                        this.BindSellContractByDataView(dst, intIndex);
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('请输入正确的页码数！')</script>";
                    }
                }
                catch
                {
                    this.lblJs.Text = "<script>alert('请输入数字类型的页码！')</script>";
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请输入要跳转的页码！')</script>";
            }
        }
    }

    protected void ibtnRef_Click(object sender, ImageClickEventArgs e)
    {
        int intCommand = Int32.Parse(((ImageButton)sender).CommandName);

        if (intCommand == 0)//刷新主表
        {
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();
            string strUserID = cls_Property.SetOrGetUserID;

            this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
        }
        else//刷新从表
        {
            DataGrid dgrd = new DataGrid();
            string strCm_No = "";
            int intItems = this.dgrdResult.Items.Count;

            for (int i = intItems - 1; i >= 0; i--)//找当前可见的子DataGrid
            {
                Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                if (panItem.Visible)
                {
                    dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                    strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                    break;
                }
            }

            ClsBillCancelDAL cls_SellManage = new ClsBillCancelDAL();
            DataSet dst = cls_SellManage.GetSellContractDataSetChild(strCm_No);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                this.BindSellContractChildByDataView(dgrd, dst, 0);
            }
        }
    }

    protected void dgrdResult_ItemCreated(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType.ToString() == "Item" || e.Item.ItemType.ToString() == "AlternatingItem")
        {
            DataGrid dgrdChildResult = (DataGrid)e.Item.FindControl("dgrdChildResult");

            //子DataGrid注册事件
            dgrdChildResult.ItemDataBound += new DataGridItemEventHandler(dgrdChildResult_ItemDataBound);
        }
    }

    private void ControlButtonVisible(string UserLogID, string CurrPageID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetCurrUserButtonPopedom(UserLogID, CurrPageID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            int intCount = dst.Tables[0].Rows.Count - 1;

            for (int i = intCount; i >= 0; i--)
            {
                int intButtonID = Int32.Parse(dst.Tables[0].Rows[i][2].ToString());

                switch (intButtonID)
                {
                    case 0:
                        this.panAdd.Visible = true;
                        break;
                    case 1:
                        this.hidButtonEdit.Value = intButtonID.ToString();
                        break;
                    case 2:
                        this.panDelete.Visible = true;
                        break;
                    case 3:
                        this.lbtnDelete1.Enabled = true;
                        break;
                    case 4:
                        this.panAudit.Visible = true;
                        break;
                    case 5:
                        this.hidButtonOAudit.Value = intButtonID.ToString();
                        break;
                    case 6:
                        this.panRef.Visible = true;
                        break;
                    case 7:
                        this.panSearch.Visible = true;
                        break;
                    case 8:
                        break;
                    case 9:
                        this.panQuery.Visible = true;
                        break;
                    case 10:
                        this.lbtnNotAudit.Enabled = true;
                        break;
                    case 11:
                        this.lbtnAuditing.Enabled = true;
                        break;
                    case 12:
                        this.lbtnEndAudit.Enabled = true;
                        break;
                    case 13:
                        break;
                    case 14:
                        break;
                    case 15:
                        this.lbtnNotCnacel.Enabled = true;
                        break;
                    case 16:
                        this.lbtnEndCnacel.Enabled = true;
                        break;
                    case 17:
                        break;
                    case 18:
                        break;
                    case 19:
                        this.lbtnAll.Enabled = true;
                        break;
                    case 20:
                        break;
                }
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (!IsPostBack)
            {
                ////////////////按钮权限控制 Begin /////////////////////////
                string strCurrPageID = this.Page.Request.Params["PageID"];
                this.hidCurrPageID.Value = strCurrPageID;
                this.ControlButtonVisible(strUserID, strCurrPageID);
                //////////////////////  End ///////////////////////////////

                this.GetSellContractInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else
            {
                this.lblJs.Text = "";//清空Js脚本
            }

            this.ibtnDelete0.Attributes.Add("onClick", "return confirm('您真的要删除所选的项吗？');");
            this.lbtnDelete0.Attributes.Add("onClick", "return confirm('您真的要删除所选的项吗？');");
            this.lbtnDelete1.Attributes.Add("onClick", "return confirm('彻底删除将无法恢复数据。您真的要删除所选的项吗？');");
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void ibtnDelete0_Click(object sender, ImageClickEventArgs e)
    {
        int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    public void lbtnQuery_Click(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

            this.GetSellContractInfoByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void ImgbtnNotAudit_Click(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

            this.GetSellContractInfoByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    #endregion

}
